package com.example.frank.test2;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

public class HelpActivity extends AppCompatActivity{

    ViewPager viewPager;
    View view1,view2,view3,view4,view5,view6,view7;
    private List<View>pagelist;
    private Button btn;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.help);

        viewPager = (ViewPager) findViewById(R.id.help_pager);
        LayoutInflater inflater = getLayoutInflater();
        view1 = inflater.inflate(R.layout.help_layout, null);
        view2 = inflater.inflate(R.layout.help_layout2, null);
        view3 = inflater.inflate(R.layout.help_layout3, null);
        view4 = inflater.inflate(R.layout.help_layout4, null);
        view5 = inflater.inflate(R.layout.help_layout5,null);
        view6 = inflater.inflate(R.layout.help_layout6,null);
        view7 = inflater.inflate(R.layout.help_layout7,null);

        pagelist = new ArrayList<View>();// 将要分页显示的View装入数组中
        pagelist.add(view1);
        pagelist.add(view2);
        pagelist.add(view3);
        pagelist.add(view4);
        pagelist.add(view5);
        pagelist.add(view7);
        pagelist.add(view6);

        viewPager.setAdapter(new ViewPagerAdatper(pagelist));

        btn = view6.findViewById(R.id.goback);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(HelpActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });

        Intent intent = getIntent();
        int page = intent.getIntExtra("page",0);//第一个参数是取值的key,第二个参数是默认值
//        设置ViewPager转到指定的界面
        viewPager.setCurrentItem(page);

    }
}


